"""__author__=晏"""
import pymysql

# 获取数据库连接
def get_connection():
    host = '47.107.105.179'
    port = 3306
    user = 'root'
    password = 'akslll1998YQT'
    database = 'maoyan'
    db = pymysql.connect(host, user, password, database, charset='utf8', port=port)
    return db


# 获取游标
def get_cursor(con):
    cursor = con.cursor()
    return cursor


#关闭数据库连接
def close_connection(con):
    con.close()


# 插入数据
def save_db2(con, cursor, data_dict):
    sql = 'insert into movie (title, releasetime, actor, ranks, score, cover) values ("%s", "%s", "%s", "%s", "%s", "%s")' % (data_dict['title'],data_dict['releasetime'],data_dict['actor'],data_dict['ranks'],data_dict['score'],data_dict['cover'])
    print(sql)
    cursor.execute(sql)
    con.commit()


# 可以避免一定的sql注入问题
def save_db(con, cursor, data_dict):
    sql = 'insert into movie (title, releasetime, actor, ranks, score, cover) values (%s, %s, %s, %s, %s, %s)'
    print(sql)
    cursor.execute(sql, (data_dict['title'],data_dict['releasetime'],data_dict['actor'],data_dict['ranks'],data_dict['score'],data_dict['cover']))
    con.commit()





